<template>
	<view class="vip-bg">
		<view class="title-page">
			<view :style="{ height: statusBarHeight }" class="uni-status-bar">
			</view>
			<view class="title-block">
				<image :src="leftIcon" @tap="leftClick" class="left-img"></image>
				<view class="title-center">
					会员成长体系
				</view>
			</view>
		</view>
		
		<view :style="{height:statusBarHeightTwo}"></view>
		
		<!-- 用户列表 -->
		<view class="user-info">
			<view class="txt-block">
				<view class="info-nums">{{userInfo.integral}}</view>
				<view class="info-txt">成长值</view>
			</view>

			<view class="user-center">
				<view class="user-block">
					<view class="user-img">
						<image :src="userInfo.headportrait" class="user-img"></image>
					</view>
				</view>
				<view class="user-txt">
					<view class="title">{{userInfo.name}}</view>
				</view>
			</view>

			<view class="txt-block">
				<view class="info-nums">-5</view>
				<view class="info-txt">成长值/天</view>
			</view>

			<view class="user-absolute" @click="ruleDescriptionClick">
				会员说明
			</view>
		</view>
		<!-- 对应的等级 -->
		<view class="leave-block">
			<image :src="leaveImg" class="leave-img"></image>
			<view class="leave-txt">
				<view class="leave-txt-one width-block">
					<view class="one-txt" :class="indexCurrent==0?'select-white':''">
						{{list[0].vip_name}}
					</view>
					<view class="two-txt">
						最高{{list[0].integral}}积分
					</view>
				</view>
				<view class="leave-txt-two width-block">
					<view class="one-txt" :class="indexCurrent==1?'select-white':''">
						{{list[1].vip_name}}
					</view>
					<view class="two-txt">
						最高{{list[1].integral}}积分
					</view>
				</view>
				<view class="leave-txt-three width-block">
					<view class="one-txt" :class="indexCurrent==2?'select-white':''">
						{{list[2].vip_name}}
					</view>
					<view class="two-txt">
						最高{{list[2].integral}}积分
					</view>
				</view>
				<view class="leave-txt-four width-block">
					<view class="one-txt" :class="indexCurrent==3?'select-white':''">
						{{list[3].vip_name}}
					</view>
					<view class="two-txt">
						最高{{list[3].integral}}积分
					</view>
				</view>
			</view>
		</view>
		<!-- 对应的等级 -->

		<swiper class="swiper" circular :autoplay="false" :current='indexCurrent' @change='swiperChange'
			next-margin="38rpx" previous-margin="38rpx">
			<swiper-item v-for="(item,index) in list">
				<view class="vip-open" :style="{backgroundImage:'url('+itemLst[index].img+')'}">
					<view class="left-block">
						<view class="left-one">{{item.vip_name}}</view>
						<view class="left-two">消费充值,享更多会员权益</view>
						<view class="left-progress"></view>
					</view>
					<view class="right-block">
						<view class="right-btn" @tap="topUpClick">立即开通</view>
						<image :src="bangIcon" class="bang-icon"></image>
					</view>
				</view>
			</swiper-item>
		</swiper>

		<view class="vip-hint-txt" v-if="indexCurrent!=3">
			<view class="hint-one-txt">
				<view class="txt">{{list[indexCurrent].vip_name}}权益</view>
			</view>
			<view class="lst-block">
				<!-- <scroll-view scroll-x="true" class="kite-classify-scroll"> -->
				 
					<view class="item" @tap="vipItemClick()" v-for="(itemTwo,itemTwoIndex) in list[indexCurrent].vip_explain">
						<image :src="itemTwo.image" class="item-img"></image>
						<view class="item-txt">
							<view class="txt-one">{{itemTwo.title}}</view>
						</view>
					</view>
			 
				<!-- </scroll-view> -->
			</view>
		</view>
		<view class="vip-hint-txt" v-else>
			
			<image src="http://oss.youkutongcheng.com/test/bny/bnyvip4.jpg"  mode="widthFix" style="width: 100%;"></image>
		</view>
		<view class="btn-block">
			<image src="@/static/vip/btn/1.png" class="left-img"></image>
			<view class="txt-block">
				<view class="left-txt" @tap="shareClick">专属邀请函</view>
				<view class="right-txt" @tap="topUpClick">立即开通</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				indexCurrent: 0,
				bangIcon: require('@/static/my/bangIcon.png'),
				userInfo: {},
				topImgLeft: 'left:44rpx',
				itemLst: [
					{
						title: '初级养殖主',
						img: 'http://oss.youkutongcheng.com/test/index0.png',
					},
					{
						title: '中级农场主',
						img: 'http://oss.youkutongcheng.com/test/index1.png',
					},
					{
						title: '高级大酋长',
						img: 'http://oss.youkutongcheng.com/test/bnyvip2.jpg',
					},
					{
						title: '特别投资人',
						img: 'http://oss.youkutongcheng.com/test/index2.png',
					}
				],
				list: [],
				schedule: 0,
				statusBarHeight: 20,
				statusBarHeightTwo: 20,
				leftIcon: require('@/static/vip/left-icon.png'),
				leaveImg: require('@/static/vip/leave/leave1.png')
			}
		},
		onLoad() {
			// this.getUserVipList()
			this.init()
			this.userInfo = uni.getStorageSync("userInfo")
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo')
		},
		mounted() {
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px'
			this.statusBarHeightTwo = (uni.getSystemInfoSync().statusBarHeight + 44) + 'px'
		},
		methods: {
			getSchedule() {
				var schedule = 100 / this.list[this.indexCurrent].integral;
				return schedule;
			},
			leftClick() {
				uni.navigateBack()
			},
			getVipName() {
				var name = "普通用户"
				for (var i = 0; i < this.list.length; i++) {
					if (this.userInfo.integral > this.list[i].integral) {
						name = this.list[i].vip_name
					}
				}
				return name;
			},
			getUserVipList() {
				var self = this;
				//商品分类获取	
				uni.request({
					url: self.serviceUrl + '/app-yytc-backstage/getUserVipList',
					method: "GET",
					success: (res) => {
						if (res.data.code == 200) {
							var list = res.data.data.list;
							for (var i = 0; i < list.length; i++) {
								if (list[i].vip_explain) {
									list[i].vip_explain = JSON.parse(list[i].vip_explain)
								} else {
									list[i].vip_explain = []
								}
							}
							self.list = list;
							self.initProgress()
						}
					},
					fail() {

					}
				})
				//商品分类获取				
			},
			init() {
				var self = this;
				this.$http('common.userVipList').then(res => {
					var list = res.data.list;
					for (var i = 0; i < list.length; i++) {
						if (list[i].vip_explain) {
							list[i].vip_explain = JSON.parse(list[i].vip_explain)
						} else {
							list[i].vip_explain = []
						}
					}
					self.list = list;
					self.itemClick(0)
				})
			},
			initProgress() {
			 
			},
			itemClick(index) {
				this.indexCurrent = index
				if (this.indexCurrent == 0) {
					this.topImgLeft = 'left:44rpx'
				}
				if (this.indexCurrent == 1) {
					this.topImgLeft = 'left:232rpx'
				}
				if (this.indexCurrent == 2) {
					this.topImgLeft = 'right:232rpx'
				}
				if (this.indexCurrent == 3) {
					this.topImgLeft = 'right:44rpx'
				}

				var schedule = this.userInfo.integral / this.list[this.indexCurrent].integral * 100;
				if (schedule > 100) {
					schedule = 100;
				}
				this.schedule = schedule;
			},
			//充值页面
			topUpClick() {
				uni.navigateTo({
					url: '/pages/topUp/topUp'
				})
			},
			ruleDescriptionClick(){
					uni.navigateTo({
						url:'/pages/ruleDescription/ruleDescription'
					})
			},
			//邀请码
			shareClick() {
				uni.navigateTo({
					url: '/pages/promotion/share'
				})
			},
			swiperChange(e) {
				this.indexCurrent = e.detail.current
				this.changeLeaveImg(this.indexCurrent)
			},
			changeLeaveImg(index) {
				let leaveImg;
				switch (index) {
					case 0:
						leaveImg = require('@/static/vip/leave/leave1.png')
						break;
					case 1:
						leaveImg = require('@/static/vip/leave/leave2.png')
						break;
					case 2:
						leaveImg = require('@/static/vip/leave/leave3.png')
						break;
					case 3:
						leaveImg = require('@/static/vip/leave/leave4.png')
						break;
				}
				this.leaveImg = leaveImg
			},
			vipItemClick(item) {
				  
				 uni.setStorageSync('vipInfo',this.list[this.indexCurrent])
				uni.navigateTo({
					url: '/pages/members/members'
				})
			}
		}
	}
</script>

<style lang="scss">
	.vip-bg {
		// height: 100%;
		width: 100%;
		background-image: url('@/static/vip/bg.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		
		padding-bottom: 700rpx;
	}
	.kite-classify-scroll {
			width: 100%;
			overflow: hidden;
			white-space: nowrap;
		}

	.title-page {
		position: fixed;
		left: 0;
		right: 0;
		z-index: 999;

		.uni-status-bar {
			height: 20px;
		}

		.title-block {
			font-size: 32rpx;
			font-weight: 500;
			height: 80rpx;
			color: white;
			// color: rgba(0, 0, 0, 1);
			display: flex;
			align-items: center;

			.left-img {
				margin-left: 24rpx;
				width: 42rpx;
				height: 40rpx;
				flex: none;
			}

			.title-center {
				flex: auto;
				padding-right: 60rpx;
				// border: 1rpx solid red;
				width: 100%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

	}

	.user-info {
		margin-top: 60rpx;
		height: 264rpx;
		display: flex;
		align-items: center;

		position: relative;

		.user-absolute {
			position: absolute;
			width: 154rpx;
			height: 56rpx;
			background: linear-gradient(90deg, rgba(252, 233, 210, 1) 0%, rgba(254, 207, 150, 1) 100%);
			box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
			border-top-left-radius: 46rpx;
			border-bottom-left-radius: 46rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: rgba(47, 41, 45, 1);
			right: 0rpx;
			top: -10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.txt-block {
			width: 30%;
			text-align: center;
			box-sizing: border-box;
			flex: none;

			.info-nums {
				font-size: 48rpx;
				font-weight: 500;
				color: rgba(255, 255, 255, 1);
			}

			.info-txt {
				margin-top: 4rpx;
				color: rgba(171, 170, 155, 1);
			}
		}

		.user-center {
			flex: auto;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.user-block {
				border-radius: 50%;
				width: 164rpx;
				height: 164rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border: 4rpx solid rgba(248, 236, 193, 0.14);

				.user-img {
					position: relative;
					flex: none;
					width: 144rpx;
					height: 144rpx;
					border-radius: 50%;
					background-color: rgba(248, 229, 172, 1);
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.user-txt {
				margin-top: 24rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: rgba(255, 255, 255, 1);
			}
		}


		.right-info {
			margin-left: 24rpx;

			.title {
				font-size: 36rpx;
				font-weight: 500;
				color: rgba(255, 255, 255, 1);
			}

			.tel {
				margin-top: 14rpx;
				opacity: 0.6;
				font-size: 28rpx;

				font-weight: 400;

				line-height: 28rpx;
				color: rgba(255, 255, 255, 1);
			}
		}

	}

	.progress-block {
		margin: 40rpx 24rpx 24rpx;

		.progress-no {
			height: 12rpx;
			border-radius: 36rpx;
			background: rgba(236, 228, 225, 0.59);
			position: relative;

			.show-nums {
				position: absolute;
				padding: 0 14rpx;
				height: 36rpx;
				border-radius: 8rpx;
				// left: 50%;
				top: -12rpx;
				text-align: center;
				background: rgba(248, 230, 173, 1);
				font-size: 24rpx;
				font-weight: 400;
				line-height: 36rpx;
				color: rgba(0, 0, 0, 1);
			}

			.progress-width {
				position: absolute;
				left: 0;
				height: 100%;
				// width: 50%;
				background: linear-gradient(90deg, rgba(235, 238, 243, 1) 0%, rgba(240, 202, 141, 1) 99.75%);
				border-radius: 36rpx;
			}

			.progress-one {
				position: absolute;
				left: 12%;
				height: 100%;
				width: 5rpx;
				background: black;
			}

			.progress-two {
				position: absolute;
				left: 32%;
				height: 100%;
				width: 5rpx;
				background: black;
			}

			.progress-three {
				position: absolute;
				left: 50%;
				height: 100%;
				width: 5rpx;
				background: black;
			}

			.progress-four {
				position: absolute;
				left: 70%;
				height: 100%;
				width: 5rpx;
				background: black;
			}

			.progress-five {
				position: absolute;
				left: 86%;
				height: 100%;
				width: 5rpx;
				background: black;
			}
		}

		.hint-block {
			left: calc(50% - 50rpx);
			display: flex;
			padding-top: 6rpx;
			padding-left: 12rpx;
			position: absolute;
			top: -78rpx;
			// background-image: url('../../static/vip/hint.png');
			background-size: 200rpx 50rpx;
			background-repeat: no-repeat;
			width: 220rpx;
			height: 70rpx;

			.hint-txt {
				flex: auto;
				color: white;
				font-size: 20rpx;
				position: relative;
				font-weight: 400;

				.question-class {
					position: absolute;
					z-index: 999;
					margin-left: 4rpx;
					margin-right: 6rpx;
					margin-top: 2rpx;
					width: 24rpx;
					height: 24rpx;

				}
			}


		}

		.progress-lst {
			margin-top: 44rpx;

			.item {
				margin-left: 44rpx;
				font-size: 28rpx;
				font-weight: 500;
				line-height: 20rpx;
				color: rgba(153, 153, 153, 1);
				height: 20rpx;
				text-align: center;
				display: inline-block;

				.txt-one {
					font-size: 28rpx;
					font-weight: 500;
				}

				.txt-two {
					font-size: 20rpx;
					font-weight: 400;
					margin-top: 14rpx;
				}
			}

			.selected-item {
				color: rgba(240, 202, 141, 1);
			}
		}
	}

	.leave-block {
		width: 100%;
		height: 180rpx;
		position: relative;

		.leave-img {
			height: 90rpx;
			width: 100%;
		}

		.leave-txt {
			position: absolute;
			left: 0;
			right: 0;
			color: rgba(97, 97, 90, 1);
			display: flex;
			align-items: center;
			font-size: 20rpx;
			font-weight: 400;
			justify-content: center;
		}

		.width-block {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			width: 25%;
		}

		.select-white {
			color: rgba(255, 255, 255, 1);
		}

		.two-txt {
			margin-top: 7rpx;
		}

		.leave-txt-one {
			color: rgba(97, 97, 90, 1);
			margin-top: -20rpx;
		}

		.leave-txt-two {
			color: rgba(171, 170, 155, 1);
		}

		.leave-txt-three {
			color: rgba(171, 170, 155, 1);
		}

		.leave-txt-four {
			margin-top: -20rpx;
			color: rgba(97, 97, 90, 1);
		}
	}

	.swiper {
		height: 400rpx;
	}

	.vip-open {
		box-sizing: border-box;
		margin-top: 34rpx;
		margin-left: 24rpx;
		margin-right: 24rpx;
		height: 340rpx;
		background-repeat: no-repeat;
		background-size: 100% 340rpx;
		display: flex;
		align-items: flex-end;
		padding-bottom: 24rpx;

		.left-block {
			flex: 1;
			margin-left: 24rpx;
			margin-top: 44rpx;
			height: 100%;

			.left-one {
				margin-top: 74rpx;
				font-size: 52rpx;
				font-weight: 700;
				color: rgba(51, 30, 7, 1);
			}

			.left-two {
				margin-top: 24rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(148, 118, 65, 1);
			}

			.left-progress {
				margin-top: 40px;
				width: 168rpx;
				height: 16rpx;
				border-radius: 40rpx;
				background: linear-gradient(90deg, rgba(226, 204, 166, 1) 0%, rgba(178, 147, 96, 1) 100%);
			}
		}

		.right-block {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: flex-end;
			justify-content: flex-end;
			margin-right: 44rpx;
			height: 100%;
			position: relative;


			.right-txt {
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(110, 67, 21, 1);
			}

			.bang-icon {
				width: 186rpx;
				height: 268rpx;
				position: absolute;
				top: 0;
			}

			.right-btn {
				margin-top: 24rpx;
				display: inline-block;
				padding: 9rpx 40rpx;
				height: 58rpx;
				text-align: center;
				line-height: 58rpx;
				color: rgba(252, 250, 224, 1);
				font-size: 28rpx;
				border-radius: 72rpx;
				background: rgba(58, 56, 66, 1);
				font-weight: 400;

			}
		}
	}

	.vip-hint-txt {
		height: 770rpx;
		margin-right: 24rpx;
		margin-left: 24rpx;
		margin-top: 34rpx;
		border-radius: 8rpx;


		.hint-one-txt {
			padding-top: 24rpx;
			display: flex;
			align-items: center;

			.left-hint {
				width: 188rpx;
				height: 4rpx;
				background: linear-gradient(90deg, rgba(248, 230, 173, 0) 0%, rgba(248, 230, 173, 0.6) 100%);
				flex: none;
			}

			.txt {

				flex: auto;
				margin: 0 12rpx;
				color: #fff;
				font-size: 32rpx;
				font-weight: 600;
			}

			.right-hint {
				flex: none;
				width: 188rpx;
				height: 4rpx;
				background: linear-gradient(270deg, rgba(248, 230, 173, 0) 0%, rgba(248, 230, 173, 0.6) 100%);
			}
		}
	}

	.lst-block {
		display: flex;
		flex-wrap: wrap;
		margin-top: 32rpx;

		.item {
			width: 25%;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 24rpx;

			.item-img {
				width: 112rpx;
				height: 112rpx;
				background: rgba(245, 222, 195, 0.06);
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;

				.img {
					width: 56rpx;
					height: 66rpx;
				}
			}

			.item-txt {
				margin-top: 24rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.txt-one {
					font-size: 28rpx;
					font-weight: 700;
					line-height: 28rpx;
					color: rgba(255, 255, 255, 1);
				}

				.txt-two {
					font-size: 24rpx;
					font-weight: 400;
					line-height: 24rpx;
					color: rgba(248, 230, 173, 1);
					margin: 20rpx 0;
				}

				.txt-three {
					font-size: 24rpx;
					font-weight: 400;
					line-height: 24rpx;
					color: rgba(255, 255, 255, 0.3);

					span {
						color: rgba(248, 230, 173, 1);
						font-size: 24rpx;
						font-weight: 400;
					}
				}

				.txt-other {
					color: rgba(255, 255, 255, 0.3);
				}
			}
		}
	}

	.btn-block {
		margin-top: 30rpx;
		margin-left: 34rpx;
		margin-right: 34rpx;
		background-image: url('@/static/vip/btn/2.png');
		background-repeat: no-repeat;
		height: 88rpx;
		background-size: 100% 88rpx;
		bottom: 24rpx;
		position: fixed;
		left: 0;
		right: 0;

		.left-img {
			width: 50%;
			height: 100%;
			margin-left: -4rpx;
		}

		.txt-block {
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			display: flex;
			align-items: center;

			.left-txt {
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				font-size: 28rpx;
				font-weight: 500;
				color: rgba(47, 41, 45, 1);
			}

			.right-txt {
				flex: 1;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				font-weight: 500;
				color: rgba(255, 206, 147, 1);

			}
		}
	}
</style>
